package com.object.module.didi.frontendcontrolller;

import com.object.configuration.utils.PageUtils;
import com.object.configuration.utils.Q;
import com.object.module.didi.entity.DdOrderFormEntity;
import com.object.module.didi.service.DdOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 订单
 *
 * @author 小🌤
 * @email 1578442339@qq.com
 * @date 2021-10-30 15:57:53
 */
@RestController
@RequestMapping("/didi/orderform")
public class FrontendDdOrderFormController {
    @Autowired
    private DdOrderFormService ddOrderFormService;



    /**
     * 全部列表查询
     */
    @GetMapping("/all")
    public Q all() {
        List<DdOrderFormEntity> list = ddOrderFormService.listAll();
        return Q.ok().put("list", list);
    }

    /**
     *  根据用户urId 全部列表查询
     */
    @RequestMapping("/all/{urId}")
    public Q Userall(@PathVariable ("urId")Integer urId) {
        List<DdOrderFormEntity> list = ddOrderFormService.Userall(urId);
        return Q.ok().put("list", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{ofId}")
    public Q info(@PathVariable("ofId") String ofId) {
        DdOrderFormEntity ddOrderForm = ddOrderFormService.getById(ofId);
        return Q.ok().put("ddOrderForm", ddOrderForm);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Q save(@RequestBody(required = false) DdOrderFormEntity ddOrderForm) {
       ddOrderForm.setOfRedPacket(ddOrderForm.getOfRedPackets());
        boolean flag = ddOrderFormService.saveForm(ddOrderForm);
        return flag ? Q.ok() : Q.error();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Q update(@RequestBody DdOrderFormEntity ddOrderForm) {
        DdOrderFormEntity ddOrderFormEntity = ddOrderFormService.getById(ddOrderForm.getOfId());
        ddOrderFormEntity.setOfState(ddOrderForm.getOfState());
        ddOrderFormService.updateById(ddOrderFormEntity);
        return Q.ok();
    }


}
